<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">预付记录</ui:define>
    <ui:define name="content">


        <h:form id="prepayForm">
            <p:dialog header="操作执行中,请稍候" widgetVar="doing" modal="true" closable="false" resizable="false"
                      draggable="false"/>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:columnToggler datasource="statisticRecordDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton value="新增" actionListener="#{businessPrepayListBean.onAdd()}"
                                         oncomplete="PF('adding').show();" process="@this" update="@form"
                                         icon="fa fa-plus" rendered="#{security:areAllGranted('BUSINESS_SECURITY')}">
                        </p:commandButton>
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         onstart="PF('doing').show()"
                                         actionListener="#{businessPrepayListBean.count()}"
                                         update="@form"/>
                        <p:commandButton value="重置" actionListener="#{businessPrepayListBean.onReset()}"
                                         icon="fa fa-refresh"
                                         process="@this" update="@form"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         ajax="false">
                            <p:dataExporter type="xls" target="statisticRecordDataTable" fileName="预付记录" postProcessor="#{businessMainListBean.postProcessXLS}"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-g ui-fluid" style="padding-top: 30px;">
                <div class="ui-g-12">
                    <div class="ui-g-12 card">
                        <h1>查询条件</h1>
                        <div class="ui-g-1">
                            <p:outputLabel value="主体名称"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="productId" value="#{businessPrepayListBean.$.companyName}"
                                             filter="true" updateLabel="true"
                                             filterMatchMode="contains">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems value="#{businessPrepayListBean.companyList}"
                                               var="dic"
                                               itemLabel="#{dic.channelMain}" itemValue="#{dic.channelMain}"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="付款日期"/>
                        </div>
                        <div class="ui-g-3">
                            <p:calendar
                                    id="startTime" styleClass="autoWidthCalendar"
                                    value="#{businessPrepayListBean.$.startTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATE_FORMAT')}"/>
                            <span>—</span>
                            <p:calendar
                                    id="endTime" styleClass="autoWidthCalendar"
                                    value="#{businessPrepayListBean.$.endTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATE_FORMAT')}"/>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="主体类型"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="mainType" value="#{businessPrepayListBean.$.mainType}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems value="#{businessPrepayListBean.dictionaries[DictionaryCode.BUSINESS_MAIN_TYPE]}"
                                               var="dic"
                                               itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="付款方式"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu value="#{businessPrepayListBean.$.payType}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{businessPrepayListBean.dictionaries[DictionaryCode.SETTLEMENT_PAY_MODE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-1">
                        <p:outputLabel value="付款类别"/>
                    </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu value="#{businessPrepayListBean.$.prepayType}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{businessPrepayListBean.dictionaries[DictionaryCode.BUSINESS_PREPAY_TYPE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="开票状态"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="billStatus" value="#{businessPrepayListBean.$.billStatus}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItem itemLabel="未核对" itemValue="0"/>
                                <f:selectItem itemLabel="已核对" itemValue="1"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="支付账号"/>
                        </div>
                        <div class="ui-g-3">
                            <p:inputText id="payAccount" value="#{businessPrepayListBean.$.payAccount}"/>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="操作人"/>
                        </div>
                        <div class="ui-g-3">
                            <p:inputText id="updator" value="#{businessPrepayListBean.$.updator}"/>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="收票总金额合计"/>
                        </div>
                        <div class="ui-g-3">
                            <p:outputLabel
                                    value="#{businessPrepayListBean.allPrepayIncome}"
                                    disabled="true"/>
                        </div>

                    </div>

                    <div class="ui-g-12 card">
                        <p:dataTable id="statisticRecordDataTable"
                                     style="width: 100%;text-align:center"
                                     var="record"
                                     value="#{businessPrepayListBean.lazyDataModel}"
                                     rows="#{constants:get('ROWS')}"
                                     lazy="true"
                                     paginator="true"
                                     paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                     rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                     emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                     scrollable="true"
                                     scrollWidth="97%"
                                     reflow="true"
                                     selection="#{businessPrepayListBean.selectPrepayList}" rowKey="#{record.id}"
                                     resizableColumns="true">
                            <p:column headerText="核对" exportable="false" rendered="#{security:areAllGranted('BUSINESS_SECURITY_STATUS')}">
                                <p:commandButton icon="fa fa-refresh" value="核对" style="width: 70px"
                                                 process="@this"
                                                 actionListener="#{businessPrepayListBean.onStatus(record.id)}"
                                                 update="@form">
                                    <p:confirm header="提示信息" message="是否确定核对?" icon="ui-icon-alert"/>
                                </p:commandButton>
                            </p:column>
                            <p:column headerText="操作" exportable="false" rendered="#{security:areAllGranted('BUSINESS_SECURITY')}">
                                <p:splitButton icon="fa fa-eye"
                                               process="@this"
                                               actionListener="#{businessPrepayListBean.onSee(record.id)}"
                                               oncomplete="PF('adding').show();" update="@form" rendered="#{security:areAllGranted('BUSINESS_SECURITY')}">
                                </p:splitButton>
                            </p:column>
                            <p:column headerText="预付日期">
                                <h:outputText value="#{record.prepayTime}"/>
                            </p:column>
                            <p:column headerText="主体名称">
                                <h:outputText value="#{record.companyName}"/>
                            </p:column>
                            <p:column headerText="主体类型" style="text-align:center;">
                                <h:outputText value="#{businessMainListBean.translate(DictionaryCode.BUSINESS_MAIN_TYPE,record.mainType)}"/>
                            </p:column>
                            <p:column headerText="付款方式" style="text-align:center;">
                                <h:outputText
                                        value="#{businessPrepayListBean.translate(DictionaryCode.SETTLEMENT_PAY_MODE,record.payType)}"/>
                            </p:column>
                            <p:column headerText="付款类别" style="text-align:center;">
                                <h:outputText
                                        value="#{businessPrepayListBean.translate(DictionaryCode.BUSINESS_PREPAY_TYPE,record.prepayType)}"/>
                            </p:column>
                            <p:column headerText="付款金额" style="text-align:center;">
                                <h:outputText
                                        value="#{record.prepayAmount}">
                                    <f:convertNumber pattern="###0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="付款凭证" style="text-align:center;">
                                <h:graphicImage url="#{record.payProof}" width="50px"/>
                            </p:column>
                            <p:column headerText="支付账号" style="text-align:center;">
                                <h:outputText value="#{record.bankId}"/>
                            </p:column>
                            <p:column headerText="核对状态" style="text-align:center;">
                                <h:outputText value="未核对" rendered="#{record.billStatus!=1}" style="color: red"/>
                                <h:outputText value="已核对" rendered="#{record.billStatus==1}" style="color: blue"/>
                            </p:column>
                            <p:column headerText="备注" style="text-align:center;">
                                <h:outputText value="#{record.remark}"/>
                            </p:column>
                            <p:column headerText="操作人" style="text-align:center;">
                                <h:outputText value="#{record.updator}"/>
                            </p:column>
                            <p:column headerText="操作时间" style="text-align:center;">
                                <h:outputText value="#{record.updateTime}">
                                    <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                </h:outputText>
                            </p:column>
                        </p:dataTable>
                    </div>
                </div>
            </div>
            <p:dialog header="预付记录" widgetVar="adding" modal="true" closable="true"
                      resizable="true"
                      style="position: absolute;">
                <p:outputPanel id="add-dialog">
                    <div class="ui-g ui-fluid" style="width:1000px;">
                        <div class="ui-g-2">
                            <p:outputLabel value="主体名称"/>
                        </div>
                        <div class="ui-g-4">
                            <p:selectOneMenu value="#{businessPrepayListBean.settlementPrepay.companyId}"
                                             filter="true" updateLabel="true"
                                             filterMatchMode="contains">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems value="#{businessPrepayListBean.companyList}"
                                               var="dic"
                                               itemLabel="#{dic.channelMain}" itemValue="#{dic.id}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-2">
                            <p:outputLabel value="付款方式"/>
                        </div>
                        <div class="ui-g-4">
                            <p:selectOneMenu value="#{businessPrepayListBean.settlementPrepay.payMode}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{businessPrepayListBean.dictionaries[DictionaryCode.SETTLEMENT_PAY_MODE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-2">
                            <p:outputLabel value="预付日期"/>
                        </div>
                        <div class="ui-g-4">
                            <p:calendar
                                    value="#{businessPrepayListBean.settlementPrepay.prepayTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATE_FORMAT')}">
                            </p:calendar>
                        </div>

                        <div class="ui-g-2">
                            <p:outputLabel value="付款金额"/>
                        </div>
                        <div class="ui-g-4">
                            <p:inputNumber value="#{businessPrepayListBean.settlementPrepay.prepayAmount}">
                            </p:inputNumber>
                        </div>

                        <div class="ui-g-2">
                            <p:outputLabel value="付款类别"/>
                        </div>
                        <div class="ui-g-4">
                            <p:selectOneMenu value="#{businessPrepayListBean.settlementPrepay.payType}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{businessPrepayListBean.dictionaries[DictionaryCode.BUSINESS_PREPAY_TYPE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-2">
                            <p:outputLabel value="付款凭证"/>
                        </div>
                        <div class="ui-g-1">
                            <p:graphicImage url="#{businessPrepayListBean.settlementPrepay.payProof}" width="80"/>
                        </div>
                        <div class="ui-g-3">
                            <p:fileUpload fileUploadListener="#{businessPrepayListBean.onUploadPayProof}"
                                          mode="advanced"
                                          fileLimit="1"
                                          auto="true"
                                          fileLimitMessage="只能上传一个文件"
                                          invalidFileMessage="不支持上传文件类型"
                                          invalidSizeMessage="文件过大"
                                          sizeLimit="#{constants:get('UPLOAD_FILE_SIZE')}"
                                          allowTypes="/(\.|\/)(#{constants:get('UPLOAD_FILE_SUFFIX')})$/"
                                          label="上传" update="@this add-dialog" process="@this add-dialog"/>
                        </div>

                        <div class="ui-g-12" style="padding: 0">
                            <div class="ui-g-2">
                                <p:outputLabel value="备注"/>
                            </div>
                            <div class="ui-g-10">
                                <p:inputText value="#{businessPrepayListBean.settlementPrepay.remark}"/>
                            </div>
                        </div>

                        <div class="ui-g-12">
                            <p:commandButton value="保存" style="float: right"
                                             actionListener="#{businessPrepayListBean.onSave()}"
                                             process="@this add-dialog" rendered="#{security:areAllGranted('BUSINESS_SECURITY')}"/>
                        </div>
                    </div>
                </p:outputPanel>
            </p:dialog>
        </h:form>
    </ui:define>
</ui:composition>